﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _6_1_Struct
{
    enum E_LightType
    {
        None = 0,
        LT_1 = 1,
        LT_2 = 2,
        LT_3 = 4,
        LT_4 = 8,
        LT_5 = 16,
        LT_6 = 32,
        LT_7 = 64,
        LT_8 = 128,
        ALL = 255,
    }
    enum E_WeekType
    {
        Mon = 1,
        Tue,
        Wed,
        Thu,
        Fri,
        Sat,
        Sun,
    }
    enum E_SexType
    {
        None,
        Man,
        Women,
    }

    

    struct Score
    {
        public float English;
        public float Chinese;
    }
    struct Student
    {
        public static int Index;
        public int ID;
        public string Name;
        public E_SexType SexType;
        public int Age;
        //public float Score;
        public Score Score;
        public string Addr;
        public override string ToString()
        {
            return "Student ID:" + ID + " Name:" + Name + " E:" + Score.English + " C:" + Score.Chinese;
        }
    } 
    class Program
    {
        private static E_LightType Light = E_LightType.LT_1 | E_LightType.LT_2 |
                                            E_LightType.LT_3 | E_LightType.LT_4 |
                                            E_LightType.LT_5 | E_LightType.LT_6 |
                                            E_LightType.LT_7 | E_LightType.LT_8;
        //设置灯开关
        public static void SetLight(E_LightType light, bool isOpen)
        {
            if (isOpen)
                Light |= light;
            else
                Light &= ~light;
        }
        //判断灯是否开启
        public static bool IsLightOpen(E_LightType light)
        {
            return light == (Light & light);
        }

        static void Main(string[] args)
        {


            Console.WriteLine(Light);
            //关指定灯
            //Light &= ~E_LightType.LT_1;
            SetLight(E_LightType.LT_1, false);
            Console.WriteLine(Light);
            //开指定灯
            //Light |= E_LightType.LT_1;
            SetLight(E_LightType.LT_1, true);

            if (IsLightOpen(E_LightType.LT_1))
                Console.WriteLine("LT_1 Open");
            else
                Console.WriteLine("LT_1 Close");

            //关闭所有灯
            SetLight(E_LightType.ALL, false);

            //开启所有灯
            SetLight(E_LightType.ALL, true);

            Console.WriteLine(Light);
            Console.ReadKey();

            E_WeekType weekday = E_WeekType.Fri;
            weekday = (E_WeekType)1;

            weekday = weekday + 5;

            if (E_WeekType.Sun == weekday)
                Console.WriteLine("This is Sun Day.");
            else
                Console.WriteLine("This is not Sun Day.");

            Student.Index = 0;

            Student student = new Student();
            student.ID = 1;
            student.Name = "Xiao Ming";
            student.SexType = E_SexType.Man;
            student.Age = 18;
            //student.Score = 100;
            Score score = new Score();
            score.Chinese = 99;
            score.English = 59;
            //student.Score.Chinese = 100;
            //student.Score.English = 50;
            student.Score = score;
            student.Addr = "地球";
            Console.WriteLine(student);

            Student s1 = student;

            Console.WriteLine(s1);

            s1.ID = 2;
            s1.Addr = "uasitgjhsaoijgohsohkmd;jhmdsk;lhjnmds;lhknmd;slhjdso;j";
            Console.WriteLine(student);
            Console.WriteLine(s1);

            Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(student));
            Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(s1));

            Console.ReadKey();

            Console.WriteLine("--------------------------------");

            Student[] studentArray = new Student[2];
            studentArray[0] = s1;
            studentArray[1] = student;

            for (int i = 0; i < studentArray.Length; i++)
            {
                Console.WriteLine(studentArray[i]);
            }

            Console.ReadKey();
        }
    }
}
